﻿ 

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using Web.Server.Hubs;
 

namespace Web.Server.Controllers
{
    public class ConnectionHandler
    {
        private static readonly Lazy<ConnectionHandler> _instance =
            new Lazy<ConnectionHandler>(
                () => new ConnectionHandler(GlobalHost.ConnectionManager.GetHubContext<PortalHub>()));

        private readonly ConcurrentDictionary<string, long> _mapHubAccount = new ConcurrentDictionary<string, long>();

        private readonly ConcurrentDictionary<long, List<string>> _mapAccountHub =
            new ConcurrentDictionary<long, List<string>>();

        private ConnectionHandler(IHubContext hubContext)
        {
            Clients = hubContext.Clients;
            Groups = hubContext.Groups;
        }

        public static ConnectionHandler Instance
        {
            get { return _instance.Value; }
        }

        public IHubConnectionContext Clients { get; private set; }

        public IGroupManager Groups { get; private set; }

        public void SendMessageToClient(long accountid, string message)
        {
             Instance.Clients.All.message(message, 3);
             
        }
        
 
    }
}